/*
 * @Author: zhengzhuang
 * @Date: 2020-08-03 17:16:35
 * @LastEditors: zhengzhuang
 * @LastEditTime: 2020-11-19 15:36:50
 * @Description: 进行中的快车单 DispatchOrderList
 * @FilePath: /C20Driver/lib/pages/index_page/home_page/dispatch_order_list.dart
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:C20Driver/event/event_bus.dart';
import 'package:C20Driver/model/get_trip_order_info.dart';
import 'package:C20Driver/routers/navigator_util.dart';
import 'package:C20Driver/service/request.dart';

class DispatchOrderList extends StatefulWidget {
  @override
  _DispatchOrderListState createState() => _DispatchOrderListState();
}

class _DispatchOrderListState extends State<DispatchOrderList> {
  GetTripOrderInfo _dispatchList = GetTripOrderInfo(); // 进行中的订单

  var _themeModelscription;

  @override
  void initState() {
    super.initState();
    _getWaitDispatchOrderFun();

    _themeModelscription = eventBus.on<SetDispatchOrderList>().listen((event) {
      _getWaitDispatchOrderFun();
    });
  }

  /// 获取派送订单列表
  _getWaitDispatchOrderFun() async {
    GetTripOrderInfo dataInfo = await Request.getOnTripOrderByDriverId();
    setState(() {
      _dispatchList = dataInfo;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Offstage(
      offstage: _dispatchList.id == null,
      child: Card(
        child: Container(
            margin: EdgeInsets.only(
              top: ScreenUtil().setWidth(20.0),
              bottom: ScreenUtil().setWidth(20.0),
            ),
            child: _dispatchWidget()),
      ),
    );
  }

  /// 派送订单组件
  Widget _dispatchWidget() {
    String _orderTxt;
    switch (_dispatchList.status) {
      case '0000':
        _orderTxt = "订单完成,已支付";
        break;
      case '0010':
        _orderTxt = "接单(有一笔进行中的订单)";
        break;
      case '0015':
        _orderTxt = "到达乘客上车点(有一笔进行中的订单)";
        break;
      case '0020':
        _orderTxt = "接到乘客，行程中(有一笔进行中的订单)";
        break;
      case '0030':
        _orderTxt = "行程结束,报价成功,等待支付(有一笔进行中的订单)";
        break;
      case '0040':
        _orderTxt = "报价失败,不可支付(有一笔进行中的订单)";
        break;
      case '0050':
        _orderTxt = "发起收款(有一笔进行中的订单)";
        break;
      case '0060':
        _orderTxt = "订单取消";
        break;
      default:
    }
    return InkWell(
      child: Container(
        width: ScreenUtil().setWidth(690.0),
        child: Container(
          padding: EdgeInsets.only(
            left: ScreenUtil().setWidth(30.0),
            right: ScreenUtil().setWidth(30.0),
            top: ScreenUtil().setWidth(20.0),
            bottom: ScreenUtil().setWidth(20.0),
          ),
          child: Column(
            children: <Widget>[
              Row(
                children: <Widget>[
                  Text(
                    '$_orderTxt',
                    style: TextStyle(
                        fontSize: ScreenUtil().setSp(30.0),
                        color: Color.fromARGB(255, 255, 153, 0),
                        fontWeight: FontWeight.w700),
                  ),
                ],
              ),
              SizedBox(height: ScreenUtil().setWidth(20.0)),
              // Row(
              //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
              //   crossAxisAlignment: CrossAxisAlignment.center,
              //   children: <Widget>[
              //     Text(
              //       '出发日期：',
              //       style: TextStyle(
              //           fontSize: ScreenUtil().setSp(30.0),
              //           color: Colors.black,
              //           fontWeight: FontWeight.w700),
              //     ),
              //     Container(
              //       width: ScreenUtil().setWidth(400.0),
              //       child: Text(
              //         '123123',
              //         style: TextStyle(
              //             fontSize: ScreenUtil().setSp(28.0),
              //             color: Colors.black),
              //       ),
              //     ),
              //   ],
              // ),
              // SizedBox(height: ScreenUtil().setWidth(20.0)),
              // Row(
              //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
              //   crossAxisAlignment: CrossAxisAlignment.center,
              //   children: <Widget>[
              //     Text(
              //       '预计出发时间：',
              //       style: TextStyle(
              //           fontSize: ScreenUtil().setSp(30.0),
              //           color: Colors.black,
              //           fontWeight: FontWeight.w700),
              //     ),
              //     Container(
              //       width: ScreenUtil().setWidth(400.0),
              //       child: Text(
              //         '123123',
              //         style: TextStyle(
              //             fontSize: ScreenUtil().setSp(28.0),
              //             color: Colors.black),
              //       ),
              //     ),
              //   ],
              // ),
              // SizedBox(height: ScreenUtil().setWidth(20.0)),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text(
                    '出发点：',
                    style: TextStyle(
                        fontSize: ScreenUtil().setSp(30.0),
                        color: Colors.black,
                        fontWeight: FontWeight.w700),
                  ),
                  Container(
                    width: ScreenUtil().setWidth(500.0),
                    child: Text(
                      '${_dispatchList.depAre}',
                      style: TextStyle(
                          fontSize: ScreenUtil().setSp(28.0),
                          color: Colors.black),
                    ),
                  ),
                ],
              ),
              SizedBox(height: ScreenUtil().setWidth(10.0)),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Text(
                    '目标点：',
                    style: TextStyle(
                        fontSize: ScreenUtil().setSp(30.0),
                        color: Colors.black,
                        fontWeight: FontWeight.w700),
                  ),
                  Container(
                    width: ScreenUtil().setWidth(500.0),
                    child: Text(
                      '${_dispatchList.destArea}',
                      style: TextStyle(
                          fontSize: ScreenUtil().setSp(28.0),
                          color: Colors.black),
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
      onTap: () {
        print(_dispatchList.status);
        print(_dispatchList.id);
        switch (_dispatchList.status) {
          case '0010': // 司机接单
            NavigatorUtil.jump(
                context, '/pickUpPassengers?orderId=${_dispatchList.id}');
            break;
          case '0015': // 司机到达上车点
            NavigatorUtil.jump(
                context, '/pickUpPassengers?orderId=${_dispatchList.id}');
            break;
          case '0020': // 接到乘客,行程中
            NavigatorUtil.jump(
                context, '/pickUpPassengers?orderId=${_dispatchList.id}');
            break;
          default:
        }
        // Provider.of<OrderInformation>(context, listen: false).setOrderInfo(depLatitude: orderData.depLatitude, depLongitude: orderData.depLongitude);
        // /// 0010 还未支付
        // if (orderData.payState == '0010') return NavigatorUtil.jump(context, '/intercityPayment?moneyData=${orderData.totalPrice}&id=${orderData.id}').then((value) {
        //     _getWaitDispatchOrderFun();
        //   });
        // switch (orderData.state) {
        //   case '0020': // 待师傅接单
        //     NavigatorUtil.jump(context, '/intercityWaitingForOrders?orderId=${orderData.id}&longitude=${orderData.depLongitude}&latitude=${orderData.depLatitude}').then((value) {
        //       _getWaitDispatchOrderFun();
        //     });
        //     break;
        //   case '0010': // 待派单
        //     NavigatorUtil.jump(context, '/intercityWaitingForOrders?orderId=${orderData.id}&longitude=${orderData.depLongitude}&latitude=${orderData.depLatitude}').then((value) {
        //       _getWaitDispatchOrderFun();
        //     });
        //     break;
        //   case '0040': // 等待来接
        //     NavigatorUtil.jump(context, '/waitingForRide?orderId=${orderData.orderId}');
        //     break;
        //   case '0045': // 乘客在路上
        //     NavigatorUtil.jump(context, '/waitingForRide?orderId=${orderData.orderId}');
        //     break;
        //   case '0055': // 司机到达上车点
        //     Provider.of<OrderInformation>(context, listen: false).setDriverArrived();
        //     NavigatorUtil.jump(context, '/waitingForRide?orderId=${orderData.orderId}');
        //     break;
        //   case '0060': // 行程中
        //     NavigatorUtil.jump(context, '/travelProcess?orderId=${orderData.orderId}');
        //     break;
        //   default:
        // }
        // return true;
      },
    );
  }
}
